package com.graduation.sfstore.controller;

import com.graduation.sfstore.entity.TemperatureData;
import com.graduation.sfstore.server.Server;
import com.graduation.sfstore.service.TemperatureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.io.IOException;

@Controller
public class TemperatureController {

    @Autowired
    private TemperatureService temperatureService;

    private String material;

    @RequestMapping(path = "/getTemperature" , method = RequestMethod.GET)
    public String getTemperature(){



        try {
            Server server = new Server(10000);
            material = server.returndata();

        } catch (IOException e) {
            e.printStackTrace();
        }


        System.out.println("controller"+material);


        TemperatureData temperatureData = temperatureService.selectLatestTemperature();
        System.out.println(temperatureData);

        String s1 = temperatureData.getMaterial();
        String temperature = s1.substring(1,3);
        System.out.println(temperature);
        String humidity = s1.substring(3,5);
        System.out.println(humidity);

        return "";

    }


}
